# _*_ coding:utf-8 _*_
# @Time  : 2023.09.05
# @Author: zizlee
# _*_ coding:utf-8 _*_
# @Time  : 2023.09.01
# @Author: zizlee
import datetime
from typing import Union
from pydantic import BaseModel, validator


class DateRangeValidator(BaseModel):
    start_date: Union[str, None]
    end_date: Union[str, None]

    @validator('start_date')
    def validate_start_date(cls, value):
        if value is None:
            return value
        try:
            datetime.datetime.strptime(value, '%Y-%m-%d')
        except ValueError:
            return ValueError('start_date invalidate! must be `yyyy-MM-dd`')
        return value

    @validator('end_date')
    def validate_end_date(cls, value):
        if value is None:
            return value
        try:
            datetime.datetime.strptime(value, '%Y-%m-%d')
        except ValueError:
            return ValueError('end_date invalidate! must be `yyyy-MM-dd`')
        return value
